<%@page import="edu.fpt.entity.RentDetail"%>
<%@page import="edu.fpt.stub.RentDetailStub"%>
<%@page import="edu.fpt.entity.BillAll"%>
<%@page import="edu.fpt.stub.BillStub"%>
<%@page import="edu.fpt.stub.CustomerStub"%>
<%@page import="edu.fpt.entity.Room"%>
<%@page import="edu.fpt.stub.RoomStub"%>
<%@page import="java.util.List"%>
<%@page import="edu.fpt.entity.Customer"%>
<%@page import="edu.fpt.stub.HotelStub"%>
<%-- 
    Document   : orderForm
    Created on : Jan 20, 2013, 1:08:49 AM
    Author     : TuanAnh
--%>


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">       
        <link rel="stylesheet" href="css/modern.css" type="text/css" />         
        <title>Customer Management</title>  
        <script>
            function isNumberKey(evt)
            {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && charCode < 48 || charCode > 57 || charCode == 46)
                    return false;
                return true;
            }
        </script>

    </head>
    <body style="color: darkred; " bgcolor="#e4e3e3">  
        <%            
            session = request.getSession();
            String user = (String) session.getAttribute("id");
            if (user == null) {
                response.sendRedirect("LoginForm.jsp");
            } else {
        %>
        <div>
            <h1 style="color: #4D1124; margin-left: 250px">Management Information</h1>
        </div>
        <div class="progress-bar">
            <div class="bar bg-color-blue" style="width: 33%"></div>
            <div class="bar bg-color-yellow" style="width: 33%"></div>
            <div class="bar bg-color-green" style="width: 34%"></div>
        </div>
        <div style="margin-top: 15px"></div>
        <h3 style="color: black; margin-left: 30px"> Choose customer name to view information</h3>
        <div style="margin-top: 10px"></div>
        <form name="order" method="post">
            <table class="">
                <thead>
                    <tr style="background-color: #85373b"  >
                        <th style="color: white; text-align: center; width: 140px; font-size: 17px">Customer ID</th>
                        <th style="color: white; text-align: center; width: 280px; font-size: 17px">Customer Name</th>
                        <th style="color: white; text-align: center; width: 100px; font-size: 17px">Gender</th>
                        <th style="color: white; text-align: center; width: 250px; font-size: 17px">Address</th>
                        <th style="color: white; text-align: center; width: 150px; font-size: 17px">Phone</th>
                        <th style="color: white; text-align: center">Email</th>
                        <th style="color: white; text-align: center; width: 140px">Passport</th>
                    </tr>
                    <%                        
                        CustomerStub stub = new CustomerStub();
                        List<Customer> list = stub.getAllCustomer();
                        for (Customer cus : list) {
                    %>
                    <tr style="background-color: #dfb7b7">
                        <th style="color: #8e1f1f; text-align: center; width: 140px"><%= cus.getCustomerId()%></th>
                        <th style="color: #8e1f1f; text-align: center; width: 280px"><a href="Bill.jsp?dataName=<%= cus.getCustomerId()%>"><%= cus.getCustomerName()%></a></th>
                        <%                            
                            if (cus.getCustomerGender() == true) {
                        %>
                        <th style="color: #8e1f1f; text-align: center; width: 100px">Male</th>
                        <% } else {%>
                        <th style="color: #8e1f1f; text-align: center; width: 100px">Female</th>
                        <% }%>
                        <th style="color: #8e1f1f; text-align: center; width: 250px"><%= cus.getCustomerAddress()%></th>
                        <th style="color: #8e1f1f; text-align: center; width: 150px"><%= cus.getPhoneNumber()%></th>
                        <th style="color: #8e1f1f; text-align: center"><%= cus.getEmail()%></th>
                        <th style="color: #8e1f1f; text-align: center; width: 140px"><%= cus.getPasspost()%></th>
                    </tr> 
                    <%                            
                        }
                    %>
                </thead>
            </table>            
            <div style="margin-top: 30px"></div>
            <div class="input-control" style="margin-left: 100px"> Customer ID: <input type="text" name="customerID" placeholder="Customer ID" style="width:230px" required  /></div>            
            <div style="margin-top: 25px"></div>
            <div style="margin-left: 350px"><input type="submit" value="Delete" name="submit" style="background-color: #0865c2"/><span><input type="button" value="Reset" style="background-color: #e3a21a; color: white;" onclick="window.location.href='CustomerForm.jsp'"/></span><span><input type="button" value="Go Back" style="background-color: #47bf4e; color: white;" onclick="window.location.href='AdminForm.jsp'"/></span></div>            
        </form>
        <%            
            if (request.getParameter("submit") != null) {
                try {
                    String cusId = request.getParameter("customerID");
                    BillStub billStub = new BillStub();
                    List<BillAll> bill = billStub.getBill();
                    for (BillAll bi : bill) {
                        if (bi.getReserDetailId().getCustomerId().getCustomerId().equals(cusId)) {
                            billStub.delete(cusId);
                            RentDetailStub dtStub = new RentDetailStub();
                            List<RentDetail> list1 = dtStub.getAll();
                            for (RentDetail detail : list1) {
                                if (detail.getCustomerId().getCustomerId().equals(cusId)) {
                                    dtStub.delete(cusId);
                                    List<Customer> lt = stub.getAllCustomer();
                                    for (Customer cs : lt) {
                                        if (cs.getCustomerId().equals(cusId)) {
                                            stub.delete(request.getParameter("customerID"));
                                            out.println("<h3 style='color: red; margin-left: 470px;'>Delete Customer Success!</h3>");
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    out.println("<h3 style='color: red; margin-left: 470px;'>Delete Fail!. Pls enter CustomerID exist in data.</h3>");
                }
            }
        %>
        <%                
            }
        %>
    </body>
</html>
